package form;

import database.DatabaseGetters;
import log.*;

import javax.lang.model.element.Element;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JTextArea;
import javax.swing.ScrollPaneConstants;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.*;
import javax.swing.SwingUtilities;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentEvent;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTextPane;
import javax.swing.JPanel;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

//import com.jgoodies.forms.layout.FormLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import shared.Friend;
import shared.PersonList;
import visualization.CreateGraph;
import visualization.GraphRender;
import java.awt.GridLayout;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;
import java.awt.Component;
import javax.swing.Box;
import com.jgoodies.forms.layout.Sizes;

import crawler.Crawler;

import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JList;
import java.awt.Color;

import form.JCheckBoxList;
import form.WindowForm.comboSelect;

import java.awt.Font;
import java.awt.SystemColor;

public class WindowForm 
{
	public JFrame frame;
    JList listFriendCurrentPlace = null;
    JList listFriendAge = null;
	JList listFriendBirthPlace = null;
	JList listFamilyRelationName = null;
	JList listSort = null;	
	JScrollPane scrollerFriendCurrentPlace = null;
	JScrollPane scrollerSort = null;
	JScrollPane scrollerFriendAge = null;
	JScrollPane scrollerFriendBirthPlace = null;
	JScrollPane scrollerFamilyRelationName = null;
	JPanel panel_1 = null;
	JPanel renderPanel = null;	
	ArrayList<String> users = null;
	SelectedItems selectedItems = null;	
	File selectedFile = null;
	String all = null;	
	boolean justAddedInfoOnHeroku = false;	 
	PersonList<Friend> friendsList = new PersonList<Friend>(); 
	 
	public enum comboSelect
	{		
		
		friendCurrentPlace("Miasto"), 
		friendAge("Wiek"),
		friendBirthPlace("Miejsce urodzenia"), 
		familyRelationName("Stopien pokrewienstwa");		
		private String selected;
		comboSelect(String s)
		{
			this.selected = s;
		}
		
		public String getCombo()
		{
			return selected;
		}
	}
	
	/**
	 * Create the application.
	 */
	public WindowForm() 
	{
		initialize();
	}

	private void initialize() 
	{
		selectedItems = new SelectedItems();
		/**
		 * Create frame - change default 	  
		 */		
		Log.saveLog();
		frame = new JFrame("GEPHI Api");
		frame.getContentPane().setBackground(SystemColor.menu);	
		frame.validate();                // Make sure layout is ok
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);		
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		frame.setSize(screenSize.width - 200 , screenSize.height - 100);
		frame.setLocationRelativeTo(null);
	
		frame.getContentPane().setLayout(new FormLayout(new ColumnSpec[] 
		{
			FormFactory.RELATED_GAP_COLSPEC,
			ColumnSpec.decode("min:grow"),
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			ColumnSpec.decode("default:grow"),
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.PREF_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.DEFAULT_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			FormFactory.MIN_COLSPEC,
			FormFactory.RELATED_GAP_COLSPEC,
			ColumnSpec.decode("center:default"),
			ColumnSpec.decode("right:4dlu"),
			ColumnSpec.decode("max(175px;min)"),},
		new RowSpec[] {
			FormFactory.RELATED_GAP_ROWSPEC,
			RowSpec.decode("min:grow"),
			FormFactory.MIN_ROWSPEC,
			RowSpec.decode("default:grow"),
			FormFactory.DEFAULT_ROWSPEC,
			FormFactory.RELATED_GAP_ROWSPEC,
			RowSpec.decode("default:grow"),
			FormFactory.RELATED_GAP_ROWSPEC,
			FormFactory.DEFAULT_ROWSPEC,
			FormFactory.RELATED_GAP_ROWSPEC,
			RowSpec.decode("default:grow"),
			RowSpec.decode("4dlu:grow"),
			RowSpec.decode("default:grow"),
			RowSpec.decode("default:grow"),
			FormFactory.RELATED_GAP_ROWSPEC,
			FormFactory.DEFAULT_ROWSPEC,
			FormFactory.RELATED_GAP_ROWSPEC,
			FormFactory.DEFAULT_ROWSPEC,
			FormFactory.RELATED_GAP_ROWSPEC,
			FormFactory.DEFAULT_ROWSPEC,
			RowSpec.decode("4dlu:grow"),
			FormFactory.DEFAULT_ROWSPEC,
			RowSpec.decode("4dlu:grow"),
			FormFactory.RELATED_GAP_ROWSPEC,
			RowSpec.decode("default:grow"),
			FormFactory.DEFAULT_ROWSPEC,
			FormFactory.RELATED_GAP_ROWSPEC,
			FormFactory.DEFAULT_ROWSPEC,
			FormFactory.RELATED_GAP_ROWSPEC,
			FormFactory.MIN_ROWSPEC,
			FormFactory.RELATED_GAP_ROWSPEC,
			FormFactory.DEFAULT_ROWSPEC,}));
	
		
		/**
		 * Adding panel for graph render
		 */
		
		panel_1 = new JPanel();
		frame.getContentPane().add(panel_1, "2, 2, 46, 24, fill, fill");
	  	DefaultListModel defaultModel = new DefaultListModel();

	  	renderPanel = new JPanel();
	  	renderPanel.setLayout(new BorderLayout());
	  	renderPanel.setBounds(10, 11, 506, 413);        
	  	renderPanel.setVisible(true);
	  	renderPanel.add(GraphRender.get().render());
	  	panel_1.add(renderPanel); 					  	
	  	/**
	  	 * Adding comboBox and values 
	  	 */
		JPanel panel = new JPanel();
		frame.getContentPane().add(panel, "52, 2, 1, 22, fill, fill");

		JComboBox<String> comboBoxFil = new JComboBox<String>();
		comboBoxFil.setFont(new Font("Segoe Print", Font.PLAIN, 11));
		comboBoxFil.setBackground(SystemColor.inactiveCaption);
		frame.getContentPane().add(comboBoxFil, "54, 9, center, center");
		comboBoxFil.addItem(WindowForm.comboSelect.friendCurrentPlace.getCombo());
		comboBoxFil.addItem(WindowForm.comboSelect.friendAge.getCombo());
		comboBoxFil.addItem(WindowForm.comboSelect.friendBirthPlace.getCombo());
			
		comboBoxFil.addItemListener(new ItemListener()
		{
			@Override
			public void itemStateChanged(ItemEvent e) {
				// TODO Auto-generated method stub
				if (e.getStateChange() == ItemEvent.SELECTED)
		        {
					if(e.getItem() == WindowForm.comboSelect.friendCurrentPlace.getCombo())
						{
							scrollerFriendCurrentPlace.setVisible(true); 
			                scrollerFriendAge.setVisible(false); 
			                scrollerFriendBirthPlace.setVisible(false);
			            }
			            else if(e.getItem() == WindowForm.comboSelect.friendAge.getCombo())
			            {

			        	   	scrollerFriendCurrentPlace.setVisible(false);
			        	    scrollerFriendAge.setVisible(true);
			        	    scrollerFriendBirthPlace.setVisible(false);
			            }
			            else if(e.getItem() == WindowForm.comboSelect.friendBirthPlace.getCombo())
			            {
			        	   	scrollerFriendCurrentPlace.setVisible(false);
				        	scrollerFriendAge.setVisible(false);
				        	scrollerFriendBirthPlace.setVisible(true);
				        	
				        }
		         }
			}
		});			
		final JTextArea textArea = new JTextArea();
		textArea.setFont(new Font("Consolas", Font.PLAIN, 12));
		textArea.setLineWrap(true);
		textArea.setWrapStyleWord(true);
		JScrollPane scrollerText =  new JScrollPane (textArea,
                ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		Log.saveLog();
		frame.getContentPane().add(scrollerText, "2, 28, 46, 3, fill, fill");
		textArea.setText(Log.readLog().toString());
				
	   /**
       * Filling JList
       */
		listSort = new JCheckBoxList();
		listSort.setModel(setDefaultListModel(DatabaseGetters.getStringsForComboBoxes())); 
	
		
	    listFriendCurrentPlace = new JCheckBoxList();
		listFriendCurrentPlace.setModel(setDefaultListModel(NullToString(DatabaseGetters.getStringsForCheckBoxes(
					WindowForm.comboSelect.friendCurrentPlace.toString()))));
			
			
		listFriendAge = new JCheckBoxList();
		listFriendAge.setModel(setDefaultListModel(	createAgeInterval(
					DatabaseGetters.getStringsForCheckBoxes(
							WindowForm.comboSelect.friendAge.toString()))));
	
			
		listFriendBirthPlace = new JCheckBoxList();
		listFriendBirthPlace.setModel(setDefaultListModel(NullToString(
					DatabaseGetters.getStringsForCheckBoxes(
					WindowForm.comboSelect.friendBirthPlace.toString()))));
		

		scrollerSort =  new JScrollPane (listSort, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
                  ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		frame.getContentPane().add(scrollerSort, "54, 2, 1, 6, fill, fill");
		scrollerSort.setVisible(true);
		
		scrollerFriendCurrentPlace =  new JScrollPane (listFriendCurrentPlace,
					                      ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
					                      ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		frame.getContentPane().add(scrollerFriendCurrentPlace, "54, 11, 1, 13, fill, fill");
				
						
		scrollerFriendAge = new JScrollPane( listFriendAge,
								ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
								ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
	
		frame.getContentPane().add(scrollerFriendAge, "53, 11, 2, 13, fill, fill");
		scrollerFriendAge.setVisible(false);
							  
		scrollerFriendBirthPlace =  new JScrollPane (listFriendBirthPlace,
			                      	ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
			                      	ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
						
		frame.getContentPane().add(scrollerFriendBirthPlace, "53, 11, 2, 13, fill, fill");
		scrollerFriendBirthPlace.setVisible(false);			

		/**
		 * Initialize buttons
		 */

		final JButton btnDodaj = new JButton("Dodaj dane osobowe");
		frame.getContentPane().add(btnDodaj, "54, 30");
		
		final JButton btnWizualizuj = new JButton("Wizualizuj");
		frame.getContentPane().add(btnWizualizuj, "54, 28");		
			
		btnDodaj.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent event) 
			{ 
				Log.saveLog();
				try 
				{
					if(justAddedInfoOnHeroku == false)
					{
						if(JOptionPane.showConfirmDialog(null, "Klikaj�c 'OK' zgadzasz si� na dodanie swoich danych osobowych do og�lnej bazy danych aplikacji.",
							"Informacja dla u�ytkownika", JOptionPane.OK_CANCEL_OPTION) == 0)
						{
							LogOnHeroku.runHeroku("https://strong-mountain-9586.herokuapp.com/");
							justAddedInfoOnHeroku = true;
							btnDodaj.setText("Wczytaj dane z facebooka");
						}	
						Log.console("User wants to log on heroku", Log.priority.Message);
					}
					else
					{
						btnWizualizuj.setEnabled(false);
						ProgressBar.get().setValue(0);
						Crawler c = new Crawler();
						c.setPage("https://strong-mountain-9586.herokuapp.com/001.txt");
						ProgressBar.get().setValueDynamic(5);
						c.analyzer.saveAllFromFile(); 
						repaintFrame();
						Log.console("Dane zostały wczytane");
						btnDodaj.setText("Dodaj dane osobowe");
						justAddedInfoOnHeroku = false;
						// usuwanie 001.txt na serwerze
						c.setPage("https://strong-mountain-9586.herokuapp.com/del.php?del=yes");
						btnWizualizuj.setEnabled(true);
					}
				} 
				catch (Exception e) 
				{
					Log.console(e.getMessage());
				}
				Log.saveLog();
				
				textArea.setText(Log.readLog().toString());
			}
		});			
			
		btnWizualizuj.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent event) 
			{ 					
				Log.saveLog();		
				
				selectedItems.selectedCity = selectedItems.set(WindowForm.comboSelect.friendCurrentPlace.toString(),compareSelected(
				((JCheckBoxList) listFriendCurrentPlace).returnSelection(),
				DatabaseGetters.getStringsForCheckBoxes(
				WindowForm.comboSelect.friendCurrentPlace.toString())
				) );
		
				selectedItems.selectedAge = selectedItems.set(WindowForm.comboSelect.friendAge.toString(),compareSelected(
				     ((JCheckBoxList) listFriendAge).returnSelection(),
				     createAgeInterval(DatabaseGetters.getStringsForCheckBoxes(
				     WindowForm.comboSelect.friendAge.toString()))
				     ) );
		
				selectedItems.selectedBorn = selectedItems.set(WindowForm.comboSelect.friendBirthPlace.toString(),compareSelected(
					((JCheckBoxList) listFriendBirthPlace).returnSelection(),
					DatabaseGetters.getStringsForCheckBoxes(
					WindowForm.comboSelect.friendBirthPlace.toString())
					) );
			
				selectedItems.selectedUser = selectedItems.set("SOURCE_ACCOUNT",
						compareSelected(((JCheckBoxList) listSort).returnSelection(),
								DatabaseGetters.getStringsForComboBoxes()));
				Log.console("Parameters for filtering has been chosen", Log.priority.Message);
				CreateGraph graf = CreateGraph.get(); 
                graf.clearGraph(); 
                graf.reCreateGraph();
                friendsList.clear();
                friendsList.addAll(new ArrayList<Friend>(DatabaseGetters.getAllFriendsParametrized(selectedItems))); 
                graf.setData(friendsList, selectedItems);        
                graf.generateGraphFile();                        
                panel_1.remove(0); 
                panel_1.add(GraphRender.get().render());    
                frame.setSize(frame.getWidth()+1, frame.getHeight()+1);
                
				textArea.setText(Log.readLog().toString());						
			}			
		});
			
				
		/**
		 * Making barMenu - initialize component
		 */

		JMenuBar menuBar = new JMenuBar();
		frame.setJMenuBar(menuBar);
		
		JMenu mnPlik = new JMenu("Plik");
		menuBar.add(mnPlik);
		
		
		JMenu mnBazaDanych = new JMenu("Wy�wietl");
		mnPlik.add(mnBazaDanych);
		
		JMenuItem mntmadujZPliku = new JMenuItem("Statystyki");
		mnBazaDanych.add(mntmadujZPliku);
		
		JMenuItem mntmWyjcie = new JMenuItem("Wyj\u015Bcie");
		mnPlik.add(mntmWyjcie);
		
		JMenu mnProject = new JMenu("Projekt");
		menuBar.add(mnProject);
		
		JMenuItem mnOProg = new JMenuItem("O programie");
		mnProject.add(mnOProg);

		/**
		 * Adding ActionListeners for barMenu
		 */
		mntmadujZPliku.addActionListener(new ActionListener() 
		{  
			@Override
			public void actionPerformed(ActionEvent event)
			{ 
				Statistics stats = new Statistics(friendsList);
				stats.generateStatistics();
				readPDF("statistics.pdf");
			}
		});  				
		mnBazaDanych.add(mntmadujZPliku);	
				
		mntmWyjcie.addActionListener(new ActionListener() 
		{  
			@Override
			public void actionPerformed(ActionEvent event)
			{ 
				System.exit(0);
			}
		});  				
				
		mnOProg.addActionListener(new ActionListener() 
		{  
			@Override
			public void actionPerformed(ActionEvent event) 
			{ 
				 WindowFormAbout windowFormAbout = new WindowFormAbout();
				 windowFormAbout.frame.setVisible(true);
			}
		});  			
	}
	
	/**
	 * 
	 * @param array of string from database
	 * @return list model
	 */
	public DefaultListModel<String> setDefaultListModel(ArrayList<String> array)
	{
		 DefaultListModel defModel = new DefaultListModel();  
		 Iterator it = Arrays.asList(array).iterator();
	     for(String element : array)
	     defModel.addElement (element);
	     return defModel;
	}
	
	/**
	 * 
	 * @param list of elements for CheckBoxes
	 * @return list with changed parameter (Null to String)
	 */
	public ArrayList<String> NullToString(ArrayList<String> list)
	{		
		try
		{
			if(list.contains("NULL")) list.remove("NULL");
			list.add("Pozosta�e");
		}
		catch(NullPointerException e)
		{
			JOptionPane.showMessageDialog(null, e);
		}
		return list;
	}
	
	
	/**
	 * Create age interval from age list
	 * @param ageList
	 * @return
	 */
	public ArrayList<String> createAgeInterval(List<String> ageList)
	{
		int interval = 0;
		ArrayList<String> divide = new ArrayList<String>();
		
		try
		{
			interval = Integer.parseInt(ageList.get(0));
			while(interval <= Integer.parseInt(ageList.get(ageList.size()-1)))
			{		
				divide.add(Integer.toString(interval)+'-'+Integer.toString(5+interval));
				interval += 5;		
			}
		}
		catch(NullPointerException ex)
		{
			JOptionPane.showMessageDialog(null, ex);
		}
		return divide;		
	}	
	
	/**
	 * 
	 * @param compIndex include indexes of selected checkboxes
	 * @param compName include name of elements from database
	 * @return list of selected names of elements
	 */
	public ArrayList<String> compareSelected(ArrayList<String> compIndex, ArrayList<String> compName)
	{
		int index = 0;
		ArrayList<String> returnValue = new ArrayList<String>();
		
		if(compName.contains("NULL") && compName.size()>1 )
		{
			index = compName.indexOf("NULL");			
			for(String c : compIndex)
			{
				Log.console(c);
				if(Integer.parseInt(c)<index)
					//NORMALNIE DODAJ
					returnValue.add(compName.get(Integer.parseInt(c)));				
				else if(Integer.parseInt(c)>=index && Integer.parseInt(c)<compName.size()-1 )				
					returnValue.add(compName.get(Integer.parseInt(c)+1));				
				if(Integer.parseInt(c) == compName.size()-1) 
					returnValue.add("NULL");				
			}
		}
		else 
		{
			for(String c : compIndex)
			{	
				returnValue.add(compName.get(Integer.parseInt(c)));
			}
		}
		return returnValue;
	}

	/**
	 * 
	 * @param compIndex - index of selected CheckBoxes
	 * @param compName - Name of all parameters in database 
	 * @return list of name of selected Checkboxes
	 */
	public ArrayList<String> compareSelectedAge(ArrayList<String> compIndex, ArrayList<String> compName)
	{
		ArrayList<String> returnValue = new ArrayList<String>();
		Log.console(compIndex.size() + ": rozmiar z indeksami");
		Log.console(compName.size() + ": rozmiar z nazwami");
		for(String c : compIndex)
		{
			Log.console(c);
			returnValue.add(compName.get(Integer.parseInt(c)));
		}				
		return returnValue;
	}
	
	public void readPDF(String url)
	{
		try 
		{		 
			if ((new File(url)).exists())
			{	
				Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
				p.waitFor();	
			} 
			else 
			{
				System.out.println("File is not exists");	
			}	
			System.out.println("Done");	
		} 
		catch (Exception ex) 
		{
			ex.printStackTrace();
		}
	}	
	
	/**
	 * Repainting checkboxes and combobox. 
	 */
	public void repaintFrame()
	{
		try
		{
			//listFriendAge = new JCheckBoxList();
			listFriendAge.removeAll();
			listFriendAge.setModel(setDefaultListModel(
					createAgeInterval(
					DatabaseGetters.getStringsForCheckBoxes(
							WindowForm.comboSelect.friendAge.toString()))));
			scrollerFriendAge.removeAll();
			scrollerFriendAge = new JScrollPane( listFriendAge,
					ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
					ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		
			frame.getContentPane().add(scrollerFriendAge, "51, 11, 2, 13, fill, fill");
			scrollerFriendAge.setVisible(false);
			//scrollerFriendAge.repaint();
			//scrollerFriendAge.revalidate();
			listFriendBirthPlace.removeAll();
			listFriendBirthPlace.setModel(setDefaultListModel(NullToString(
					DatabaseGetters.getStringsForCheckBoxes(
					WindowForm.comboSelect.friendBirthPlace.toString()))));
			scrollerFriendBirthPlace.removeAll();
			scrollerFriendBirthPlace =  new JScrollPane (listFriendBirthPlace,
		          	ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
		          	ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
		
			frame.getContentPane().add(scrollerFriendBirthPlace, "51, 11, 2, 13, fill, fill");
			listSort.removeAll();
			//listSort = new JCheckBoxList();
			listSort.setModel(setDefaultListModel(DatabaseGetters.getStringsForComboBoxes())); 
			scrollerSort.removeAll();
			scrollerSort =  new JScrollPane (listSort, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
					                      ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
			frame.getContentPane().add(scrollerSort, "51, 2, 2, 6, fill, fill");		
			frame.repaint();
			frame.revalidate();
			scrollerFriendAge.setVisible(false);
			scrollerFriendBirthPlace.setVisible(false);
			Log.console("Odświeżono parametry", Log.priority.Message);	
		}
		catch(Exception e)
		{
			Log.console("Problem z odďż˝wieďż˝aniem parametrďż˝w ", Log.priority.Error);
		}
	}
}